﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Web.Framework;
using System.ServiceModel;
using Web.Framework.Svc;
using CrmContacto.Contracts;
using CrmContacto.WebApp.ServiceReferenceApiAuth;
using CrmContacto.Contracts.Contracts.Search;
using CrmContacto.Contracts.Contracts;
using CrmContacto.Contracts.Contracts.Misc;
using CrmContacto.ServiceFactory;
using CrmContacto.Contracts.Services;
using CrmContacto.Contracts.Contracts.Localization;
using CrmContacto.Contracts.Promociones;


namespace Web.CrmContacto.Code
{
    public class WebServiceHelper
    {
        public ServiceOptions ServiceOptionsDefault
        {
            get;
            set;
        }

        public static bool Authenticate(int applicationId, int companyId, string userName, string password)
        {
            AuthApiClient client = new AuthApiClient();
            bool isAuthenticated = false;
            try
            {
                isAuthenticated = client.ValidateUser(applicationId, companyId, userName, password);
                client.Close();
            }
            catch (Exception ex)
            {
                if (client.State != System.ServiceModel.CommunicationState.Closed)
                {
                    client.Abort();
                }
                throw ex;
            }

            return isAuthenticated;
        }

        public static List<Company> GetCompanies(int applicationId)
        {
            AuthApiClient client = new AuthApiClient();
            List<Company> companies = new List<Company>();

            try
            {
                companies.AddRange(client.GetCompanies(applicationId));
                client.Close();
            }
            catch (Exception ex)
            {
                if (client.State != System.ServiceModel.CommunicationState.Closed)
                {
                    client.Abort();
                }
                throw ex;
            }

            return companies;
        }

        public static List<string> GetOperationsForUser(int applicationId, int companyId, string userName)
        {
            AuthApiClient client = new AuthApiClient();
            List<string> operations = new List<string>();

            try
            {
                operations.AddRange(client.GetOperationsForUser(applicationId, companyId, userName));
                client.Close();
            }
            catch (Exception ex)
            {
                if (client.State != System.ServiceModel.CommunicationState.Closed)
                {
                    client.Abort();
                }
                throw ex;
            }

            return operations;
        }

        public static List<AdUser> GetUsers(int applicationId, int companyId, string userName)
        {
            AuthApiClient client = new AuthApiClient();
            List<AdUser> adUserList = new List<AdUser>();
            try
            {
                adUserList.AddRange(client.GetUsers(applicationId, companyId, userName));
                client.Close();
            }
            catch (Exception ex)
            {
                if (client.State != System.ServiceModel.CommunicationState.Closed)
                {
                    client.Abort();
                }
                throw ex;
            }

            return adUserList;
        }

        //public static List<MaestroBase> GetCampaniasActivas(int empresaId)
        //{
        //    ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
        //    return service.GetCampaniasActivas(empresaId);
        //    //CrmContactoAdminServiceClient client = new CrmContactoAdminServiceClient();
        //    //try
        //    //{
        //    //    var listMaestros = client.GetCampaniasActivas(empresaId);
        //    //    client.Close();
        //    //    return listMaestros;
        //    //}
        //    //catch (Exception ex)
        //    //{
        //    //    if (client.State != System.ServiceModel.CommunicationState.Closed)
        //    //    {
        //    //        client.Abort();
        //    //    }
        //    //    throw ex;
        //    //}
        //}      

        public static List<MaestroBase> GetTipoDocumento(int empresaId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetTipoDocumento(empresaId);
            //CrmContactoAdminServiceClient client = new CrmContactoAdminServiceClient();
            //try
            //{
            //    var listMaestros = client.GetTipoDocumento(empresaId);
            //    client.Close();
            //    return listMaestros;
            //}
            //catch (Exception ex)
            //{
            //    if (client.State != System.ServiceModel.CommunicationState.Closed)
            //    {
            //        client.Abort();
            //    }
            //    throw ex;
            //}
        }

        public static List<Pais> GetPaises()
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            PaisSearch search = new PaisSearch();
            search.LoadProvincia = false;
            return service.GetPaisesDto(new ServiceOptions(), search);
            //CrmContactoAdminServiceClient client = new CrmContactoAdminServiceClient();
            //try
            //{
            //    var listMaestros = client.GetPaises();
            //    client.Close();
            //    return listMaestros;
            //}
            //catch (Exception ex)
            //{
            //    if (client.State != System.ServiceModel.CommunicationState.Closed)
            //    {
            //        client.Abort();
            //    }
            //    throw ex;
            //}
        }

        public static List<MaestroBase> GetProvincias(int paisId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetProvincias(paisId);
            //CrmContactoAdminServiceClient client = new CrmContactoAdminServiceClient();
            //try
            //{
            //    var listMaestros = client.GetProvincias(paisId);
            //    client.Close();
            //    return listMaestros;
            //}
            //catch (Exception ex)
            //{
            //    if (client.State != System.ServiceModel.CommunicationState.Closed)
            //    {
            //        client.Abort();
            //    }
            //    throw ex;
            //}
        }

        public static List<MaestroBase> GetCategoriasDeContacto(MaestroBaseSearch searchMaestroBase)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetCategoriasDeContacto(searchMaestroBase);
            //CrmContactoAdminServiceClient client = new CrmContactoAdminServiceClient();
            //try
            //{
            //    var listMaestros = client.GetCategoriasDeContacto(empresaId);
            //    client.Close();
            //    return listMaestros;
            //}
            //catch (Exception ex)
            //{
            //    if (client.State != System.ServiceModel.CommunicationState.Closed)
            //    {
            //        client.Abort();
            //    }
            //    throw ex;
            //}
        }

        public static List<MaestroBase> GetListasDeDistribucion(int empresaId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetListasDeDistribucion(empresaId);

            //CrmContactoAdminServiceClient client = new CrmContactoAdminServiceClient();
            //try
            //{
            //    var listMaestros = client.GetListasDeDistribucion(empresaId);
            //    client.Close();
            //    return listMaestros;
            //}
            //catch (Exception ex)
            //{
            //    if (client.State != System.ServiceModel.CommunicationState.Closed)
            //    {
            //        client.Abort();
            //    }
            //    throw ex;
            //}
        }

        public MaestroBase SaveCategoria(MaestroBase categoria, int empresaId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveCategoria(this.ServiceOptionsDefault, categoria, empresaId);
        }

        public void EliminarCategoria(int categoriaId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarCategoria(this.ServiceOptionsDefault, categoriaId);
        }

        public ClienteSearchResult GetCustomers(CustomerSearchParam searchParam)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetCustomers(this.ServiceOptionsDefault, searchParam);
        }

        public void EliminarContactos(CustomerSearchParam searchParam)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarContactos(this.ServiceOptionsDefault, searchParam);
        }

        public ClienteBitacora SaveCustomerBitacora(ClienteBitacora clienteBitacora)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveCustomerBitacora(this.ServiceOptionsDefault, clienteBitacora);
        }

        public static List<CompanyConfiguration> GetCompanyConfigurations()
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetCompanyConfigurations();
        }

        public static Dictionary<string, string> GetCompanyConfigurationKeyValues(int companyId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetCompanyConfigurationKeyValues(companyId);
        }

        public static Cliente GetCustomerById(ServiceOptions options, int customerId, ClienteByIdOptions clientOptions)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetCustomerById(options, customerId, clientOptions);
        }

        public Cliente SaveCustomer(Cliente customer)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveCustomer(this.ServiceOptionsDefault, customer);
        }

        public static ClienteCantidades GetCantidadDeContactos(int empresaId, DateTime mesEnCurso)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetCantidadDeContactos(empresaId, mesEnCurso);
        }

        public List<ClienteWrap> SaveCustomerList(List<ClienteWrap> customerList)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveCustomerList(this.ServiceOptionsDefault, customerList);
        }

        //public List<Campania> GetCampanias(CampaniaSearch search)
        //{
        //    ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
        //    return service.GetCampanias(this.ServiceOptionsDefault, search);   
        //}

        //public Campania SaveCampania(Campania campania)
        //{
        //    ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
        //    return service.SaveCampania(this.ServiceOptionsDefault, campania); 
        //}

        //public void EliminarCampania(int campaniaId)
        //{
        //    ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
        //    service.EliminarCampania(this.ServiceOptionsDefault, campaniaId); 
        //}

        //public List<CampaniaInstancia> GetCampaniaInstancia(CampaniaInstanciaSearch search)
        //{
        //    ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
        //    return service.GetCampaniaInstancia(this.ServiceOptionsDefault, search);   
        //}

        //public CampaniaInstancia SaveCampaniaInstancia(CampaniaInstancia campaniaInstancia)
        //{
        //    ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
        //    return service.SaveCampaniaInstancia(this.ServiceOptionsDefault, campaniaInstancia); 
        //}

        //public void EliminarCampaniaInstancia(int campaniaInstanciaId)
        //{
        //    ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
        //    service.EliminarCampaniaInstancia(this.ServiceOptionsDefault, campaniaInstanciaId); 
        //}

        public List<ListaDeDistribucion> GetListaDeDistribucion(ListaDistribucionSearch search)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetListaDeDistribucion(this.ServiceOptionsDefault, search);
        }

        public ListaDeDistribucion SaveListaDeDistribucion(ListaDeDistribucion listaDistribucion)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveListaDeDistribucion(this.ServiceOptionsDefault, listaDistribucion);
        }

        public void EliminarListaDeDistribucion(int listaDistribucionId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarListaDeDistribucion(this.ServiceOptionsDefault, listaDistribucionId);
        }

        public void EliminarContactoDeListaDeDistribucion(int listaDistribucionId, int contactoId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarContactoDeListaDeDistribucion(this.ServiceOptionsDefault, listaDistribucionId, contactoId);
        }

        public void AddListaDistribucionesACampania(int campaniaId, List<int> listaDistribucionIds)
        {
            //ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            //service.AddListaDistribucionesACampania(this.ServiceOptionsDefault, campaniaId, listaDistribucionIds); 
        }

        public void EliminarListaDistribucionDeCampania(int campaniaId, int listaDistribucionId)
        {
            //ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            //service.EliminarListaDistribucionDeCampania(this.ServiceOptionsDefault, campaniaId, listaDistribucionId); 
        }

        public void AddListaDistribucionesAConctacto(int contactoId, List<int> listaDistribucionIds)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.AddListaDistribucionesAConctacto(this.ServiceOptionsDefault, contactoId, listaDistribucionIds);
        }

        public void ActivarEntidad(string entidad, int? estado, int entidadId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.ActivarEntidad(this.ServiceOptionsDefault, entidad, estado.Value, entidadId);
        }

        public List<PlanDeMarketing> GetPlanesDeMarketing(PlanDeMarketingSearch search)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetPlanesDeMarketing(this.ServiceOptionsDefault, search);
        }

        public void EliminarPlanDeMarketing(int planDeMarketingId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarPlanDeMarketing(this.ServiceOptionsDefault, planDeMarketingId);
        }

        public PlanDeMarketing SavePlanDeMarketing(PlanDeMarketing planDeMarketingCurrent)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SavePlanDeMarketing(this.ServiceOptionsDefault, planDeMarketingCurrent);
        }

        public void EliminarAccionDeMarketing(int accionDeMarketingId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarAccionDeMarketing(this.ServiceOptionsDefault, accionDeMarketingId);
        }

        public List<AccionDeMarketing> GetAccionesDeMarketing(AccionDeMarketingSearch search)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetAccionesDeMarketing(this.ServiceOptionsDefault, search);
        }

        public AccionDeMarketing SaveAccionDeMarketing(AccionDeMarketing accionDeMarketing)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveAccionDeMarketing(this.ServiceOptionsDefault, accionDeMarketing);
        }

        public AccionDeMarketingComunicacion SaveAccionDeMarketingComunicacion(AccionDeMarketingComunicacion accionDeMarketing)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveAccionDeMarketingComunicacion(this.ServiceOptionsDefault, accionDeMarketing);
        }

        public void EliminarListaDistribucionDeAccionDeMarketing(int accionDeMarketingId, int listaDistribucionId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarListaDistribucionDeAccionDeMarketing(this.ServiceOptionsDefault, accionDeMarketingId, listaDistribucionId);
        }

        public void EliminarAccionDeMarketingRelacionadaDeAccionDeMarketing(int accionDeMarketingId, int accionDeMarketingRelacionadaId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarAccionDeMarketingRelacionadaDeAccionDeMarketing(this.ServiceOptionsDefault, accionDeMarketingId, accionDeMarketingRelacionadaId);
        }

        public void EliminarResultadoDeAccionDeMarketing(int accionDeMarketingId, int resultadoId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarResultadoDeAccionDeMarketing(this.ServiceOptionsDefault, accionDeMarketingId, resultadoId);
        }

        public void EliminarPuntoDeVentaRelacionadoDeAccionDeMarketing(int accionDeMarketingId, int puntoDeVentaId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarPuntoDeVentaRelacionadoDeAccionDeMarketing(this.ServiceOptionsDefault, accionDeMarketingId, puntoDeVentaId);
        }

        public void AddAmbitoAAccionDeMarketing(int accionDeMarketingId, List<int> puntosDeVentaIds)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.AddAmbitoAAccionDeMarketing(this.ServiceOptionsDefault, accionDeMarketingId, puntosDeVentaIds);
        }

        public void AddAccionDeMarketingRelacionadaAAccionDeMarketing(int accionDeMarketingId, List<int> accionesIds)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.AddAccionDeMarketingRelacionadaAAccionDeMarketing(this.ServiceOptionsDefault, accionDeMarketingId, accionesIds);
        }       

        public void AddListaDistribucionesAAccionDeMarketing(int accionDeMarketingId, List<int> listaDistribucionIds)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.AddListaDistribucionesAAccionDeMarketing(this.ServiceOptionsDefault, accionDeMarketingId, listaDistribucionIds);
        }

        public List<ReportingConfiguration> GetReportingConfiguration(string name, int empresaId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetReportingConfiguration(name, empresaId);
        }

        public static List<Lenguaje> ObtenerLenguajes()
        {
            ILocalization service = ServiceFactory.Instance.GetLocalizationService();
            return service.ObtenerLenguajes();
        }

        public static Lenguaje ObtenerLenguajeById(string Id)
        {
            ILocalization service = ServiceFactory.Instance.GetLocalizationService();
            return service.ObtenerLenguajeById(Id);
        }

        public static Lenguaje SaveLenguaje(Lenguaje lenguaje)
        {
            ILocalization service = ServiceFactory.Instance.GetLocalizationService();
            return service.SaveLenguaje(lenguaje);
        }

        public static void EliminarLenguaje(string id)
        {
            ILocalization service = ServiceFactory.Instance.GetLocalizationService();
            service.EliminarLenguaje(id);
        }

        public static PalabraClave GetPalabraClaveLenguaje(string LenguajeId, string ClaveId)
        {
            ILocalization service = ServiceFactory.Instance.GetLocalizationService();
            return service.GetPalabraClaveLenguaje(LenguajeId, ClaveId);
        }

        public static PalabraClave SavePalabraClaveLenguaje(PalabraClave palabraClave)
        {
            ILocalization service = ServiceFactory.Instance.GetLocalizationService();
            return service.SavePalabraClaveLenguaje(palabraClave);
        }

        internal List<AccionDeMarketingEmailResultado> SaveResultadosEmailAccionDeMarketing(int accionDeMarketingComunicacionId, List<AccionDeMarketingEmailResultado> resultadoList)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveResultadosEmailAccionDeMarketing(this.ServiceOptionsDefault, accionDeMarketingComunicacionId, resultadoList);
        }

        public List<AccionDeMarketingPromocion> GetAccionesDeMarketingPromocion(AccionDeMarketingSearch search)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetAccionesDeMarketingPromocion(search);
        }

        public List<AccionDeMarketingPublicidad> GetAccionesDeMarketingPublicidad(AccionDeMarketingSearch search)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetAccionesDeMarketingPublicidad(search);
        }

        public List<AccionDeMarketingPromocionRegla> GetReglasAccionDeMarketing(MaestroBaseSearch search)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetReglasAccionDeMarketing(search);
        }

        public AccionDeMarketingPromocion SaveAccionDeMarketingPromocion(AccionDeMarketingPromocion accionDeMarketing)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveAccionDeMarketingPromocion(this.ServiceOptionsDefault, accionDeMarketing);
        }

        internal AccionDeMarketingPublicidad SaveAccionDeMarketingPublicidad(AccionDeMarketingPublicidad accionDeMarketing)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveAccionDeMarketingPublicidad(this.ServiceOptionsDefault, accionDeMarketing);
        }

        public void CambiarEstadoAAccionDeMarketing(int accionDeMarketingId, int estado)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.CambiarEstadoAAccionDeMarketing(this.ServiceOptionsDefault, accionDeMarketingId, estado);
        }

        public void CambiarEstadoAPlanDeMarketing(int planDeMarketingId, int estado)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.CambiarEstadoAPlanDeMarketing(this.ServiceOptionsDefault, planDeMarketingId, estado);
        }

        public void EliminarRegla(int reglaId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarRegla(this.ServiceOptionsDefault, reglaId);
        }

        public AccionDeMarketingPromocionRegla SaveReglasAccionDeMarketing(AccionDeMarketingPromocionRegla regla)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveReglasAccionDeMarketing(this.ServiceOptionsDefault, regla);
        }

        public AccionDeMarketingComunicacionConfiguracion SaveAccionMarketingConfiguracion(AccionDeMarketingComunicacionConfiguracion configuracion)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveAccionMarketingConfiguracion(this.ServiceOptionsDefault, configuracion);
        }

        public List<AccionDeMarketingComunicacionConfiguracion> GetAccionesMarketingConfiguracion(ConfiguracionAccionMarketingSearch search)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetAccionesMarketingConfiguracion(this.ServiceOptionsDefault, search);
        }

        public void EliminarAccionMarketingConfiguracion(string configuracionId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarAccionMarketingConfiguracion(this.ServiceOptionsDefault, configuracionId);
        }

        public List<AccionDeMarketingComunicacionTipo> GetMarketingComunicacionTipo(TipoAccionDeMarketingComunicacionSearch search)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetMarketingComunicacionTipo(search);
        }

        public AccionDeMarketingComunicacionTipo SaveMarketingComunicacionTipo(AccionDeMarketingComunicacionTipo tipo)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveMarketingComunicacionTipo(this.ServiceOptionsDefault, tipo);
        }

        public void EliminarMarketingComunicacionTipo(int tipoId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarMarketingComunicacionTipo(this.ServiceOptionsDefault, tipoId);
        }
       
        public static List<PuntoDeVenta> GetPuntoDeVentaDto(PuntoDeVentaSearch search)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetPuntoDeVentaDto(new ServiceOptions(), search);
        }

        public PuntoDeVenta SavePuntoDeVentaDto(PuntoDeVenta ptoVta)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SavePuntoDeVentaDto(this.ServiceOptionsDefault, ptoVta);
        }

        public void EliminarPuntoDeVentaDto(int puntoDeVentaId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarPuntoDeVentaDto(this.ServiceOptionsDefault, puntoDeVentaId);
        }

        public List<Pais> GetPaisesDto(PaisSearch search)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetPaisesDto(this.ServiceOptionsDefault, search);
        }

        public Pais SavePaisDto(Pais pais)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SavePaisDto(this.ServiceOptionsDefault, pais);
        }

        public void EliminarPaisDto(int paisId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarPaisDto(this.ServiceOptionsDefault, paisId);
        }

        public List<Provincia> GetProvinciasDto(MaestroBaseSearch search)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetProvinciasDto(this.ServiceOptionsDefault, search);
        }

        public Provincia SaveProvinciaDto(Provincia provincia)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveProvinciaDto(this.ServiceOptionsDefault, provincia);
        }

        public void EliminarProvinciaDto(int provinciaId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarProvinciaDto(this.ServiceOptionsDefault, provinciaId);
        }

        public List<TipoMensajeBitacora> GetTipoMensajeBitacora(TipoMensajeBitacoraSearch search)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetTipoMensajeBitacora(search);
        }

        public TipoMensajeBitacora SaveTipoMensajeBitacora(TipoMensajeBitacora tipoMensaje)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveTipoMensajeBitacora(this.ServiceOptionsDefault, tipoMensaje);
        }

        public void EliminarTipoMensajeBitacora(int tipoMensajeId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.EliminarTipoMensajeBitacora(this.ServiceOptionsDefault, tipoMensajeId);
        }

        public CompanyConfiguration SaveCompanyConfiguration(CompanyConfiguration companyConfiguration)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveCompanyConfiguration(this.ServiceOptionsDefault, companyConfiguration);
        }

        public List<Producto> GetProductos(ProductoSearch search)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetProductos(this.ServiceOptionsDefault, search);
        }

        public ParticipantesSearchResult GetParticipantes(ParticipantesSearch searchParam)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.GetParticipantes(this.ServiceOptionsDefault, searchParam);
        }

        public void AddCategoriasAContactos(CustomerSearchParam searchParam, List<int> categoriasIds)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.AddCategoriasAContactos(this.ServiceOptionsDefault, searchParam, categoriasIds);
        }

        public static ResultadoInterfaceVentas GetResultadoInterfaceVentas(int empresaId)
        {
            IInterfaceVentas service = ServiceFactory.Instance.GetCrmInterfaceVentasService();
            return service.GetResultadoInterfaceVentas(empresaId);
        }

        public SubPuntoDeVenta SaveSubPuntoDeVenta(SubPuntoDeVenta subPuntoDeVenta)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            return service.SaveSubPuntoDeVenta(this.ServiceOptionsDefault, subPuntoDeVenta);
        }

        public void RemoveSubPuntoDeVentaFromPdv(int subPuntoDeVentaId)
        {
            ICrmContactoAdminService service = ServiceFactory.Instance.GetCrmContactoAdminService();
            service.RemoveSubPuntoDeVentaFromPdv(this.ServiceOptionsDefault, subPuntoDeVentaId);
        }
    }
}